﻿<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>




<div id="myToolbar5">
    <a href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-add'" onclick="toOpenAddDialog()">添加</a>
    <a href="javascript:void(0)" class="easyui-linkbutton"
       data-options="iconCls:'icon-remove'" onclick="doDelete()">批量删除</a>
</div>

<div id="addDiv5">
    <form id="addForm1" method="post"  >
        名字:<input id="addname" name="lessonName"/><br/>
    </form>
</div>

<div id="addSubmitBtn5">
    <a href="javascript:void(0)" onclick="doadd()" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">提交</a>
</div>


<script>
    $(function(){
        $("#myDatagrid5").datagrid({
            url:"${pageContext.request.contextPath}/getLessons.do",
            pagination:true,
            toolbar:"#myToolbar5",
            columns:[[
                {field:'lessonId',title:'ID',width:100},
                {field:'lessonName',title:'名字',width:100}
            ]],


        });


        $("#addDiv5").dialog({
            title:"添加课程",
            buttons:"#addSubmitBtn5",
            closed:true,
            width:300
        });
    });


    function toOpenAddDialog(){
        $("#addDiv5").dialog("open");
    }

    function doadd(){
        $("#addForm1").form("submit",{
            url:"${pageContext.request.contextPath}/addLesson.do",

            success:function(data){

                var jsObj = JSON.parse(data);
                if(jsObj.isAdd){
                    $.messager.alert('提示框',"添加成功",'info');
                    $("#addDiv5").dialog("close");
                    $("#myDatagrid5").datagrid("reload");
                }else{
                    $.messager.alert('提示框',"添加失败",'warning');
                }
            }
        });
    }

    function doDelete(){



        var allSelectedRows = $("#myDatagrid5").datagrid("getSelections");

        if(allSelectedRows.length==0){

            $.messager.alert('提示',"请选中后再删除",'warning');
        }else{
            $.messager.confirm('确认', '确认要删除吗?', function(r){
                if (r){
                    var id=new Array();
                    for(var i=0;i<allSelectedRows.length;i++){
                        id[i]=allSelectedRows[i].lessonId;
                    }
                    $.ajax({
                        data:{"id":id},
                        url:"${pageContext.request.contextPath}/deleteLesson.do",
                        type:"post",
                        traditional:true,
                        success:function(data){
                                $("#myDatagrid5").datagrid("reload");
                        }
                    });
                }
            });

        }

    }
</script>
<table id="myDatagrid5"></table>